package com.demo.lifeinfo.widget;

import android.os.CountDownTimer;
import android.widget.EditText;
import android.widget.TextView;

///验证码倒计时
public class TimeCount extends CountDownTimer {


        private TextView tvVerifcode;
        private EditText etAcode;
        public TimeCount(long millisInFuture, long countDownInterval, TextView textView, EditText editText) {
            super(millisInFuture, countDownInterval);// 参数依次为总时长,和计时的时间间隔
            this.tvVerifcode = textView;
            this.etAcode = editText;
        }

        @Override
        public void onFinish() {// 计时完毕时触发
            tvVerifcode.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
            tvVerifcode.setText("点击获取验证码");
            tvVerifcode.setClickable(true);
//            tv_verifcode.setBackgroundResource(R.drawable.btn_code);
            etAcode.setFocusable(true);
            etAcode.setFocusableInTouchMode(true);
            etAcode.requestFocus();
        }

        @Override
        public void onTick(long millisUntilFinished) {// 计时过程显示
            tvVerifcode.setText(millisUntilFinished / 1000 + "s后再次获取");
//            tv_verifcode.setBackgroundResource(R.drawable.btn_gray_code);
            tvVerifcode.setClickable(false);
        }
    }